package com.tongguan.paypos.fragment;

import android.os.Bundle;
import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.tongguan.paypos.R;
import com.tongguan.paypos.base.BaseFragment;
import com.tongguan.paypos.common.AppConstants;
import com.tongguan.paypos.utils.L;
import com.tongguan.paypos.utils.SPUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Joylive on 2016/12/15 .
 */

public class SettingPrintFragment extends BaseFragment {

    @BindView(R.id.swh_print_sd)
    SwitchCompat mSwhPrint;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_system_print, container, false);
        ButterKnife.bind(this, rootView);
        setTitle("打印设置");
        boolean isChecked = (boolean) SPUtils.getSp(frmCtx,AppConstants.SWITCH_SD,false);
        L.d("sp获取的sw状态 "+isChecked);
        mSwhPrint.setChecked(isChecked);
        initEvent();
        return rootView;
    }

    private void initEvent() {
        mSwhPrint.setOnCheckedChangeListener((buttonView, isChecked) -> {
            L.d("监听改变 ：是否打开按钮" + isChecked);
            if (isChecked){
                SPUtils.setSP(frmCtx,AppConstants.SWITCH_SD,true);
                L.d("迅联交易打开");
            }else{
                L.d("迅联交易关闭");
                SPUtils.setSP(frmCtx,AppConstants.SWITCH_SD,false);
            }

        });
    }
}
